using System;
using UnityEngine;

public class TChangeColorAction : TAction
{
	private GPObject previousObj;
	
	public TChangeColorAction (TObject o) : base (o){}
	
	public TChangeColorAction (TObject prevO, TObject o){
		previousObj = (GPObject)(prevO);
		this.tobj = o;
	}
	
	public override void undo(){
		GameObject tangible = LevelHandler.Instance.tangibles[previousObj.Id];
		if(tangible != null){
			
			switch(previousObj.Type){
			case ObjectType.LaserGenerator :
					tangible.GetComponent<LaserGeneratorHandler>().colorPicker.GetComponent<ColorPickerHandler>().colorObject(previousObj.ObjColor);
				break;
			case ObjectType.Filter :
				tangible.GetComponent<FilterHandler>().colorPicker.GetComponent<ColorPickerHandler>().colorObject(previousObj.ObjColor);
			break;
			default :
				break;
			}
			
		}
	}
	
	public override void redo(){
		GPObject gpo = (GPObject)(tobj);
		
		GameObject tangible = LevelHandler.Instance.tangibles[gpo.Id];
		if(tangible != null){
			
			switch(previousObj.Type){
			case ObjectType.LaserGenerator :
					tangible.GetComponent<LaserGeneratorHandler>().colorPicker.GetComponent<ColorPickerHandler>().colorObject(gpo.ObjColor);
				break;
			case ObjectType.Filter :
				tangible.GetComponent<FilterHandler>().colorPicker.GetComponent<ColorPickerHandler>().colorObject(gpo.ObjColor);
			break;
			default :
				break;
			}
			
		}
		
	}
	
	public override string ToString ()
	{
		return string.Format ("[TChangeColorAction] : {0}", tobj.ToString());
	}
}

